import 'package:flutter/material.dart';
import 'package:hello_flutter/base/index.dart';

class ClipWidget extends BasePage {
  const ClipWidget({super.key});

  @override
  String getPageTitle() => 'Clip';

  @override
  Widget buildBody(BuildContext context) {
    Widget avatar = Image.asset(
      'assets/images/logo.png',
      width: 60,
      height: 60,
      fit: BoxFit.cover,
    );
    return SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          avatar,
          const Divider(),
          ClipOval(
            child: avatar,
          ),
          const Divider(),
          ClipRRect(
            borderRadius: BorderRadius.circular(15),
            child: avatar,
          ),
          const Divider(),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Align(
                alignment: Alignment.topLeft,
                widthFactor: 0.5,
                child: avatar,
              ),
              Text(
                'Hello World',
                style: TextStyle(
                  color: Colors.white,
                  backgroundColor: Colors.red.withOpacity(0.5),
                ),
              ),
            ],
          ),
          const Divider(),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ClipRect(
                child: Align(
                  alignment: Alignment.topLeft,
                  widthFactor: 0.5,
                  child: avatar,
                ),
              ),
              const Text(
                'Hello World',
                style: TextStyle(
                  color: Colors.white,
                  backgroundColor: Colors.red,
                ),
              ),
            ],
          ),
          const Divider(),
          Container(
            color: Colors.red,
            width: 60,
            height: 60,
            child: ClipRect(
              clipper: MyClipper(),
              child: avatar,
            ),
          ),
        ],
      ),
    );
  }
}

class MyClipper extends CustomClipper<Rect> {

  @override
  Rect getClip(Size size) => const Rect.fromLTWH(10, 15, 40, 30);

  @override
  bool shouldReclip(covariant CustomClipper<Rect> oldClipper) => false;
}
